
import { GetIndexedDB } from '../../Utils/IndexedDB'
import { MenuConversion } from '../../Utils/Conversion'
import { BuiltInData } from '../../Config/tableOptions'
import { BaseFormButton } from '../../Utils/TableButton'
import { commonTableList } from '../../Config/tableCommon'

// TODO 入参 uuid, url, ProTableEvent, ClientData, Permission, actionRef
const Menu = async ({ ProTableEvent, ClientData }) => {
    const mapping = await GetIndexedDB('mapping')
    const get = 'getProjectMenuOldTree'

    const columns = [
        { ...commonTableList.tableName, title: '菜单名称', width: 200 },
        {
            dataIndex: 'mappingName',
            title: '映射名称',
            valueType: 'input',
            width: 200,
            render: (_, { uuid, tableName }) => (<div>{mapping[uuid] || tableName}</div>)
        },
        { ...commonTableList.sortId, rules: true },
        {
            ...commonTableList.parentUuid,
            fieldProps: {
                fieldNames: { label: 'tableName', value: 'uuid' },
                options: await MenuConversion(),
            },
        },
        {
            dataIndex: 'type',
            title: '类型',
            width: 100,
            rules: true,
            valueType: 'select',
            valueEnum: BuiltInData.MenuType,
            hideInSearch: true,
        },
        {
            dataIndex: 'pageType',
            title: '页面类型',
            valueType: 'select',
            valueEnum: ClientData.dictionary['1a7f3576-6287-4d0c-a408-baacb46f05a8'],
            rules: true,
            valueJudge: 'type',
            judgeValue: '0',
            hideInTable: true,
        },
        commonTableList.isEnabled,
        commonTableList.remark,
        {
            title: '操作',
            valueType: 'systemOperation',
            fixed: 'right',
            width: 80,
            align: 'center',
            hideInSearch: true,
            hideInAdded: true,

            hideInModify: true,
            render: (_, record) => {
                const { uuid, tableName } = record
                return [
                    <BaseFormButton
                        key='MenuMap'  // key = v4()
                        event='MenuMap'
                        ProTableEvent={ProTableEvent}
                        title="名称映射"
                        data={{ uuid, tableName, mappingName: mapping[uuid] }}
                    />,
                ]
            },
        },
    ]

    return {
        get,
        columns,
        hideInSearch: true,
        params: { pageIndex: 1, pageSize: 1000 },
    }
}

export default Menu